package cn.itsy.dao.ductype;

import cn.itsy.pojo.Duct;
import cn.itsy.pojo.Ductype;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-05-30 14:05
 */
@Repository(value = "ducTypeDaoimpl")
public class DucTypeDaoimpl implements DucTypeDao {

    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Ductype> queryDucTypeAll(String sql) {
        List<Ductype> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Ductype>(Ductype.class));
        return query;
    }

    @Override
    public Integer insertDucType(String sql, Ductype ductype) {
        int update = this.jdbcTemplate.update(sql, ductype.getId(), ductype.getTbian(), ductype.getTname());
        return update;
    }

    @Override
    public List<Duct> queryDuctById(String sql, Ductype ductype) {
        List<Duct> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Duct>(Duct.class), ductype.getId());
        return query;
    }

    @Override
    public Integer deleteDuctypeById(String sql, Ductype ductype) {
        int update = this.jdbcTemplate.update(sql, ductype.getId());
        return update;
    }

    @Override
    public Integer updateDuctNameById(String sql, Ductype ductype) {
        int update = this.jdbcTemplate.update(sql, ductype.getTbian(), ductype.getTname(), ductype.getId());
        return update;
    }
}
